package goover.unit06;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class LockDemo01 {
    public static void main(String[] args){
        Test04 t = new Test04();
        new Thread(t,"窗口1").start();
        new Thread(t,"窗口2").start();
        new Thread(t,"窗口3").start();
    }
}
class Test05 implements Runnable{
    private int sum = 10;
    private final Lock lock = new ReentrantLock();
    @Override
    public void run() {
        while (sum > 0){
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            lock.lock();
            if(sum > 0){
                System.out.println(Thread.currentThread().getName() + sum--);
                lock.unlock();
            }
        }
    }
}